#include <REGX52.H>
#include "Delay.h"
#include "LCD1602.h"
#include "IR.h"
#include "Motor.h" 
unsigned char Address;
unsigned char Command;
unsigned char Num;
unsigned char Command,Speed;
/**
 * 函    数：主函数
 * 参    数：无
 * 返 回 值：无
 */
void main()
{	
	LCD_Init();
	LCD_ShowString(1,1,"Addr  Cmd  Speed");
	LCD_ShowString(2,1,"                ");
	
	Motor_Init();
	IR_Init();
	
	while(1)
	{
		if(IR_GetDataFlag() || IR_GetRepeatFlag())	//如果收到数据帧或者收到连发帧
		{
			Address=IR_GetAddress();		//获取遥控器地址码
			Command=IR_GetCommand();		//获取遥控器命令码
			
			LCD_ShowHexNum(2,1,Address,2);	//显示遥控器地址码
			LCD_ShowHexNum(2,7,Command,2);	//显示遥控器命令码
			
			
			
			if(Command==IR_0){Speed=0;}		//根据遥控器命令码设置速度
			if(Command==IR_1){Speed=1;}
			if(Command==IR_2){Speed=2;}
			if(Command==IR_3){Speed=3;}
			
			if(Speed==0){Motor_SetSpeed(0);}	//速度输出
			if(Speed==1){Motor_SetSpeed(50);}
			if(Speed==2){Motor_SetSpeed(75);}
			if(Speed==3){Motor_SetSpeed(100);}
			
			LCD_ShowNum(2,12,Speed,3);		//显示Speed
		}
	}
}

